//
//  FPPrevueViewCell.m
//  FilmParadise
//
//  Created by lanou3g on 15/7/14.
//  Copyright (c) 2015年 DLYgroup. All rights reserved.
//

#import "FPPrevueViewCell.h"

@implementation FPPrevueViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    //间距
    CGFloat space = 10;
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //添加图片
        self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(kImageH(space), kImageH(space), kImageH(120), kImageH(80))];
        self.iconImageView.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_iconImageView];
        //添加播放标记
        self.playImageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.iconImageView.x + self.iconImageView.width - kImageW(50), self.iconImageView.y + self.iconImageView.height - kImageH(50), kImageW(30), kImageW(30))];
        self.playImageView.image = [UIImage imageNamed:@"cm2_rcd_btn_play_prs@3x"];
        [self.iconImageView addSubview:_playImageView];
        
        //添加预告label
        CGFloat prevueX = self.iconImageView.frame.origin.x + 2 * kImageH(space) + self.iconImageView.frame.size.width;
        CGFloat prevueY = self.iconImageView.frame.origin.y;
        CGFloat prevueW = kScreenWidth - 3 * kImageH(space) - self.iconImageView.frame.size.width;
        self.prevueLabel = [[UILabel alloc]initWithFrame:CGRectMake(prevueX, prevueY, prevueW, 0)];
        self.prevueLabel.numberOfLines = 0;
        [self.contentView addSubview:_prevueLabel];
        //添加详情介绍label
        self.introLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.prevueLabel.frame.origin.x, self.prevueLabel.frame.origin.y + self.prevueLabel.frame.size.height, kScreenWidth, kImageH(30))];
        self.introLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_introLabel];
    }
    return self;
}
//动态计算预告label文本的高度并赋值
- (void)adjustSubviewsWithContent:(FPPrevueModel *)model
{
  
    self.prevueLabel.text = model.movieName;
    self.introLabel.text = model.summary;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.coverImg] placeholderImage:nil completed:nil];
    CGRect bounds = [model.movieName boundingRectWithSize:CGSizeMake(kScreenWidth - 3 * kImageH(10) - self.iconImageView.frame.size.width, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16] forKey:NSFontAttributeName] context:nil];
    self.prevueLabel.font = [UIFont systemFontOfSize:16];
    CGRect frame = self.prevueLabel.frame;
    frame.size.height = bounds.size.height;
    self.prevueLabel.frame = frame;
    self.introLabel.y = self.prevueLabel.y + self.prevueLabel.height + self.iconImageView.y;
}

@end
